package Collection;

import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;

/**
 * @author yt1105
 * @version 1.0
 */
public class CollectionFor {
    @SuppressWarnings({"all"})
    public static void main(String[] args) {
        //增强for循环的本质是简化版的迭代器
        // 这个其实就是我们的简化的方法new ArrayList
        List arrayList = new ArrayList();
        arrayList.add(new Dog("小白", 2));
        arrayList.add(new Dog("小狗", 2));
        arrayList.add(new Dog("小花", 2));
        for (Object o : arrayList) {//for 循环的本质就是简化版本的迭代器其实 只不过用起来比较方便而已
            System.out.println(o);
        }
        ListIterator listIterator = arrayList.listIterator();
        while (listIterator.hasNext()) {
            Object next = listIterator.next();
            System.out.println(next);

        }


    }
}

class Dog {
    private String name;
    private int age;

    public Dog(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Dog{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
